package com.jic.data.controller;

import com.jic.common.base.vo.RestResult;
import com.jic.data.model.entity.MonSingleOneMoreGuestSaleAmount;
import com.jic.data.model.entity.MonSingleSaleAmount;
import com.jic.data.model.entity.SaleSingleSaleDetail;
import com.jic.data.model.vo.request.MonSingleOneMoreGuestSaleAmountRequest;
import com.jic.data.model.vo.request.MonSingleSaleAmountRequest;
import com.jic.data.model.vo.request.SaleSingleSaleDetailRequest;
import com.jic.data.model.vo.response.*;
import com.jic.data.service.MonSingleOneMoreGuestSaleAmountService;
import com.jic.data.service.MonSingleSaleAmountService;
import com.jic.data.service.SaleSingleSaleDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: 建投数据科技(山东)有限公司
 * @date: 2020-05-09 17:25:18
 */
@RestController
@Slf4j
@RequestMapping("/monSingleSaleAmount")
@Api(tags = " [商品销售-单品-月度")
public class MonSingleSaleAmountController {
    @Autowired
    private MonSingleSaleAmountService monSingleSaleAmountService;

    @Autowired
    private MonSingleOneMoreGuestSaleAmountService monSingleOneMoreGuestSaleAmountService;

    @Autowired
    private SaleSingleSaleDetailService saleSingleSaleDetailService;

    /**
     *
     * @param request 前端请求参数
     */
    @PostMapping("/listAll")
    @ApiOperation(value = "不分页查询 [商品销售-单品-月度-月度商品销售额&件单价] ")
    @ResponseBody
    public RestResult<HistogramChartResponse> listMonSingleSaleAmountAllRecord(@RequestBody MonSingleSaleAmountRequest request) throws Throwable {
        MonSingleSaleAmount monSingleSaleAmount = new MonSingleSaleAmount();
        BeanUtils.copyProperties(request, monSingleSaleAmount);
        HistogramChartResponse responses = monSingleSaleAmountService.listAllRecord(monSingleSaleAmount);

        return RestResult.success(responses);
    }


    /**
     * 一次客回购客客户数
     *
     * @param request 前端请求参数
     */
    @PostMapping("/list/mon/single/quantity")
    @ApiOperation(value = "一次客回购客客户数")
    @ResponseBody
    public RestResult<HistogramChartResponse> listMonSingleOneMoreGuestquantityRecord(@RequestBody MonSingleOneMoreGuestSaleAmountRequest request) throws Throwable {
        MonSingleOneMoreGuestSaleAmount monSingleOneMoreGuestSaleAmount = new MonSingleOneMoreGuestSaleAmount();
        BeanUtils.copyProperties(request, monSingleOneMoreGuestSaleAmount);
        HistogramChartResponse response = monSingleOneMoreGuestSaleAmountService.listAllRecord(monSingleOneMoreGuestSaleAmount);

        return RestResult.success(response);
    }

    /**
     * 一次客回购客销售额占比
     *
     * @param request 前端请求参数
     */
    @PostMapping("/list/mon/single/amount")
    @ApiOperation(value = "一次客回购客销售额占比")
    @ResponseBody
    public RestResult<List<PieChartResponse>> listMonSingleOneMoreGuestSaleAmountAllRecord(@RequestBody MonSingleOneMoreGuestSaleAmountRequest request) throws Throwable {
        MonSingleOneMoreGuestSaleAmount monSingleOneMoreGuestSaleAmount = new MonSingleOneMoreGuestSaleAmount();
        BeanUtils.copyProperties(request, monSingleOneMoreGuestSaleAmount);
        List<PieChartResponse> responseList = monSingleOneMoreGuestSaleAmountService.selectOneMoreAmount(monSingleOneMoreGuestSaleAmount);

        return RestResult.success(responseList);
    }



    /**
     * SALE_SINGLE_SALE_DETAIL 查询列表（不分页）
     *
     * @param request 前端请求参数
     */
    @PostMapping("/list/one/more/contrast")
    @ApiOperation(value = "商品销售-单品-月度-月度一次客回购客对比")
    @ResponseBody
    public RestResult<List<SaleSingleSaleDetailResponse>> listSaleSingleSaleDetailAllRecord(@RequestBody SaleSingleSaleDetailRequest request) throws Throwable {
        SaleSingleSaleDetail saleSingleSaleDetail = new SaleSingleSaleDetail();
        BeanUtils.copyProperties(request, saleSingleSaleDetail);
        List<SaleSingleSaleDetailResponse> responseList = saleSingleSaleDetailService.listAllRecord(saleSingleSaleDetail);

        return RestResult.success(responseList);
    }



    @PostMapping("/list/sale/")
    @ApiOperation(value = "商品销售-单品-月度-销售单品明细")
    @ResponseBody
    public RestResult<List<SaleDetailResponse<List<MonSaleSingleDetailResponse>>>> listProductSaleDetail(@RequestBody SaleSingleSaleDetailRequest request) throws Throwable {
        SaleSingleSaleDetail saleSingleSaleDetail = new SaleSingleSaleDetail();
        BeanUtils.copyProperties(request, saleSingleSaleDetail);
        List<SaleDetailResponse<List<MonSaleSingleDetailResponse>>> responseList = saleSingleSaleDetailService.listProductSaleDetail(saleSingleSaleDetail);
        return RestResult.success(responseList);
    }

}

